package com.wyt.cloud.utils.query.strategy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wyt.cloud.utils.bean.BeanUtil;
import com.wyt.cloud.utils.query.FilterMatchRuleEnum;
import com.wyt.cloud.utils.query.strategy.AbstractMatchStrategy;
import com.wyt.cloud.utils.query.strategy.QueryMatchStrategy;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;

@Service
public class IsNullStrategy extends AbstractMatchStrategy implements QueryMatchStrategy {
    @Override
    public boolean when(FilterMatchRuleEnum ruleEnum) {
        return FilterMatchRuleEnum.IS_NULL.equals(ruleEnum);
    }


    @Override
    public <T> void then(QueryWrapper<T> wrapper, Field sourceField, Object value, Field targetField) {
        wrapper.isNull(BeanUtil.camelToDownLine(getFieldName(sourceField)));
    }

}
